package main

import (
	"fmt"
	"sync"
	"time"
)

var wg sync.WaitGroup
// 写数据
func fun1(ch1 chan int){
	for i:=1;i <=10;i++{
		ch1 <- i
		fmt.Printf("写入数据%v成功",i)
		time.Sleep(time.Millisecond*500)
	}
	close(ch1)
	wg.Done()
}
func func2(ch1 chan int){
	for v:=range ch1{
		fmt.Printf("[读取]数据%v成功\n",v)
		time.Sleep(time.Millisecond*50)
	}
	wg.Done()
}
func main(){
	var ch =make(chan int,10)
	wg.Add(1) //添加一个协程
	go fun1(ch)
	wg.Add(1) //协程
	go func2(ch)
	fmt.Println("退出")
}